import numpy as np
import cv2
import time
import matplotlib.pyplot as plt
%matplotlib inline
%load_ext autoreload
#using autoreload 1 to reload all modules imported by %aimport everytime before executing the python code typed .
%autoreload 2
%aimport lane_detection, car_detection, main
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
sobel_img = lane_detection.abs_sobel_thresh(gray, thresh=(10, 200))
lane_detection.plt_images(img, 'Source image', sobel_img, 'Sobel image')
dir_binary = lane_detection.dir_threshold(gray, thresh=(np.pi/6, np.pi/2))
lane_detection.plt_images(img, 'Source image', dir_binary, 'dir Sobel image')
combined = ((sobel_img == 1) & (dir_binary == 1))
lane_detection.plt_images(sobel_img, 'sobel image', combined, 'combined Sobel image')
thresholded = lane_detection.combine_thresh(img,s_thresh=(100, 255), l_thresh=(120, 255))
lane_detection.plt_images(img, 'Source image', thresholded, 'combined threshold image')
thresholded_img, warped_img, Minv = lane_detection.warp_image_to_birdseye_view_gray(img)
lane_detection.plt_images(img, 'Source image', warped_img, 'warped image')
left_fit, right_fit,out_img, lefty, leftx, righty, rightx, ploty = lane_detection.fitlines(warped_img, nwindows=15, margin=100, minpix = 50 )
plt.imshow(out_img)
<matplotlib.image.AxesImage at 0x1f6c2b02b80>
center,left_curverad, right_curverad = lane_detection.lane_curvatures(img, lefty, leftx, righty, rightx, ploty)
print(center)
print(left_curverad)
print(right_curverad)
0.29517596785131356 1570.2880410982805 5567.999760624177
result,color_warp = lane_detection.draw_lane(img, warped_img, left_fit, right_fit, ploty, center, left_curverad, right_curverad, Minv)
lane_detection.plt_images(result, 'Output image', color_warp, 'Lane image')
processed_img = lane_detection.laneDetection_pipeline_v1(img)
plt.figure(figsize=(10,5))
plt.imshow(processed_img)
<matplotlib.image.AxesImage at 0x1f6c09502e0>
processed_img = lane_detection.laneDetection_pipeline_v2(img)
plt.figure(figsize=(10,5))
plt.imshow(processed_img)
<matplotlib.image.AxesImage at 0x1f6bf5eb9d0>
net = car_detection.getNet()
layers_name = car_detection.loadWeightsLayers(net)
print("yolo weights and layers are loaded.")
print("Layer names: ", layers_name)
yolo weights and layers are loaded. Layer names: ['yolo_82', 'yolo_94', 'yolo_106']
start_t = time.time()
layers_output = car_detection.netForwardOutput(img, net, layers_name)
print("Interface took: {}".format(time.time() - start_t))
Interface took: 1.0669240951538086
boxes = []
confidences = []
classIDs = []
idxs=[]
idxs, boxes, confidences = car_detection.getBoxes(layers_output, img)
img = car_detection.drawBoxes(idxs, boxes, confidences, img)
plt.imshow(img)
<matplotlib.image.AxesImage at 0x1f6bef40a30>
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
boxes = []
confidences = []
classIDs = []
idxs=[]
idxs, boxes, confidences = car_detection.getBoxes(layers_output, img)
img = car_detection.draw_cars(idxs,boxes,img)
img = car_detection.drawBoxes(idxs, boxes, confidences, img)
plt.imshow(img)
<matplotlib.image.AxesImage at 0x1f6bf6b8250>
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
processed_img_whole = main.pipeline_v1(img)
plt.imshow(processed_img_whole)
<matplotlib.image.AxesImage at 0x1f6c0d78310>
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
processed_img_whole = main.pipeline_v2(img)
plt.imshow(processed_img_whole)
<matplotlib.image.AxesImage at 0x1f6bf3007f0>
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
processed_img_whole = main.pipeline_v3(img)
plt.imshow(processed_img_whole)
<matplotlib.image.AxesImage at 0x1f6bf2cfc40>
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
processed_img_whole = main.pipeline_v4(img)
plt.imshow(processed_img_whole)
<matplotlib.image.AxesImage at 0x1f6c08debb0>
main.createVideo("./test_videos/challenge_video.mp4","challenge_video_output.mp4")
main.createVideo("./test_videos/challenge_video.mp4","challenge_video_output_debug_mode.mp4", "1")
main.createVideo("./test_videos/challenge_video.mp4","challenge_video_output_draw_cars.mp4","2")
main.createVideo("./test_videos/challenge_video.mp4","challenge_video_output_debug_mode_draw_cars.mp4", "3")
main.createVideo("./test_videos/project_video.mp4","project_video_output.mp4")
main.createVideo("./test_videos/project_video.mp4","project_video_output_debug_mode.mp4", "1")
main.createVideo("./test_videos/project_video.mp4","project_video_output_draw_cars.mp4", "2")
main.createVideo("./test_videos/project_video.mp4","project_video_output_debug_mode_draw_cars.mp4", "3")